package ru.elteam.web.beans.request;

import org.apache.commons.collections.MapUtils;
import org.apache.commons.collections.map.LinkedMap;
import ru.elteam.ejb.util.Debug;
import ru.elteam.logic.ProjectDescriptor;

import javax.enterprise.context.SessionScoped;
import javax.faces.model.SelectItem;
import javax.faces.model.SelectItemGroup;
import javax.inject.Named;
import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @author Nikita.Brazhnikov
 */
@Named("profile")
@SessionScoped
public class UserProfileBean implements Serializable {

	private String username;
	private static List<ProjectDescriptor> allProjects = Arrays.asList(new ProjectDescriptor[]{
		 new ProjectDescriptor(1l, "Sora no otoshimo"),
		 new ProjectDescriptor(5l, "Watashi wa tomodachi ga sukunai"),
		 new ProjectDescriptor(4l, "Higurashi no naka kori ni")
	});
	private static Map<String, String> allNotifications = MapUtils.putAll(new LinkedMap(), new Object[][]{
		 {"Severe only", "SEVERE"}, {"All my events", "USER"}, {"All available events", "ALL"}
	});


	private static SelectItemGroup hoursGroup;
	private static SelectItemGroup daysGroup;

	static {
		SelectItem[] hours = new SelectItem[] {
			 new SelectItem(1l, "1 hour"),
			 new SelectItem(2l, "2 hours"),
			 new SelectItem(5l, "5 hours")
		};
		hoursGroup = new SelectItemGroup("Hours","",false,hours);
		SelectItem[] days = new SelectItem[] {
			 new SelectItem(24l, "1 day"),
			 new SelectItem(48l, "2 days")
		};
		daysGroup = new SelectItemGroup("Days", "", false, days);
	}

	private String password;

	private boolean recieveNotifications = true;

	private List<String> selectedNotifications;

	private List<ProjectDescriptor> selectedProjects;

	private String selectedNotificationType;

	private Long[] selectedFreqs;

	private Long defaultFreq;

	private AppearanceSettings appearanceSettings = new AppearanceSettings();

	public Long getDefaultFreq() {
		return defaultFreq;
	}

	public void setDefaultFreq(Long defaultFreq) {
		this.defaultFreq = defaultFreq;
	}

	public boolean isRecieveNotifications() {
		return recieveNotifications;
	}

	public void setRecieveNotifications(boolean recieveNotifications) {
		this.recieveNotifications = recieveNotifications;
	}

	public List<String> getSelectedNotifications() {
		return selectedNotifications;
	}

	public void setSelectedNotifications(List<String> selectedNotifications) {
		this.selectedNotifications = selectedNotifications;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public List<ProjectDescriptor> getAllProjects() {
		return allProjects;
	}

	public List<ProjectDescriptor> getSelectedProjects() {
		return selectedProjects;
	}

	public void setSelectedProjects(List<ProjectDescriptor> selectedProjects) {
		this.selectedProjects = selectedProjects;
	}

	public void setSelectedNotificationType(String selectedNotificationType) {
		this.selectedNotificationType = selectedNotificationType;
	}

	public Map<String, String> getAllNotifications() {
		return allNotifications;
	}


	public String getSelectedNotificationType() {
		return selectedNotificationType;
	}

	public Long[] getSelectedFreqs() {
		return selectedFreqs;
	}

	public void setSelectedFreqs(Long[] selectedFreqs) {
		this.selectedFreqs = selectedFreqs;
	}

	public SelectItem[] getFrequences() {
		return new SelectItem[]{hoursGroup, daysGroup};
	}

	public AppearanceSettings getAppearanceSettings() {
		return appearanceSettings;
	}

	public void setAppearanceSettings(AppearanceSettings appearanceSettings) {
		this.appearanceSettings = appearanceSettings;
	}

	public String update() {
		System.out.println("Profile has been updated");
		Debug.prints("Selected notifications", selectedNotifications);
		Debug.prints("Selected projects", selectedProjects);
		return null;
	}


}
